<!--
 * @Author: zhayang
 * @LastEditors: zhayang 1063975710@qq.com
 * @Date: 2024-06-15 15:17:22
 * @LastEditTime: 2024-07-03 21:44:33
 * @Description: 日期范围选择器
-->
<template>
  <div class="days-time">
    <el-date-picker
      v-bind="$attrs"
      type="daterange"
      align="right"
      unlink-panels
      size="small"
      range-separator="至"
      start-placeholder="开始日期"
      end-placeholder="结束日期"
      :picker-options="pickerOptions"
      value-format="yyyy-MM-dd"
      popper-class="date-style"
      v-on="$listeners"
    />
  </div>
</template>

<script>
export default {
  props: {},
  data() {
    return {
      days: [],
      // 日期快捷选择
      pickerOptions: {
        shortcuts: [
          {
            text: '最近一周',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
              picker.$emit('pick', [start, end])
            }
          },
          {
            text: '最近一个月',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
              picker.$emit('pick', [start, end])
            }
          },
          {
            text: '最近三个月',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
              picker.$emit('pick', [start, end])
            }
          }
        ],
        disabledDate(time) {
          return (
            time.getTime() > Date.now() ||
            time.getTime() < Date.now() - 3600 * 1000 * 24 * 365
          )
        }
      }
    }
  },
  created() {},
  methods: {}
}
</script>

<style lang="scss" scoped></style>
